<?php

if (defined('NO_DIRECT')) {
	if (isset($_GET['i'])) {
		$datetime = date('Y-m-d H:i:s');
		$restatus_from = intval($_GET['i']);
		$status = db_result('SELECT stat_id,restat_from FROM status WHERE stat_id = '.$restatus_from);
		if ($status === false) {
			// gagal. retweet yg ga nyata
			echo 'gagal. retweet yg ga nyata';
		} else {
			$mentions = db_array('SELECT mention_who FROM mentions WHERE mention_stat = '.$status['stat_id']);
			$topics = db_array('SELECT topic_tag FROM topics WHERE topic_stat = '.$status['stat_id']);
			if ($status['restat_from'] != '0') {
				$restatus_from = $status['restat_from'];
			}
			$id_status = db_insert('INSERT INTO status (stat_date,stat_user,stat_txt,reply_stat,restat_from) VALUES ("'.$datetime.'",'.$session['user']['user_id'].',"",0,'.$restatus_from.')');
			foreach ($mentions as $mention) {
				db_insert('INSERT INTO mentions (mention_stat,mention_who) VALUES ('.$id_status.','.$mention['mention_who'].')');
			}
			foreach ($topics as $topic) {
				db_insert('INSERT INTO topics (topic_stat,topic_tag) VALUES ('.$id_status.',"'.$topic['topic_tag'].'")');
			}
			// berhasil oye oye
			echo 'berhasil oye oye';
		}
	}
}
